package com.duke.business.service.sb01.script2platform.app;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author gjy
 * @create 2025-08-14 16:32
 */
@RestController
public class ScriptController {
    @Autowired
    private ScriptService scriptService;


    //http://127.0.0.1:9111/runScript
    @GetMapping("/runScript")
    public String runScript(@RequestParam(name = "scriptDir",required = false) String scriptDir,
                            @RequestParam(name = "message", defaultValue = "来自脚本 外部 的问候") String message) throws Exception {
        if (scriptDir == null || scriptDir.isEmpty()) {
//            scriptDir = "/Users/jingyuangao/Documents/code-work/sre-share/javaagent-bash-01/business-service-sb-01/src/main/java/com/duke/business/service/sb01/script2platform/scripts";
            scriptDir = "/Users/jingyuangao/Documents/code-work/sre-share/javaagent-bash-01/business-service-sb-01/src/main/java";
        }
        ScriptRequest request = new ScriptRequest(scriptDir, message);
        scriptService.executeScript(request);
        return "执行成功 ："+ message;
    }
}
